package com.example.framework2002a;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.framework2002a.adapter.ViewPagerAdapter;
import com.example.framework2002a.bean.MyTabBean;
import com.example.framework2002a.databinding.ActivityMainBinding;
import com.example.framework2002a.view.fragment.OneFragment;
import com.example.framework2002a.view.fragment.ThreeFragment;
import com.example.framework2002a.view.fragment.TwoFragment;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;
    private ViewPagerAdapter viewPagerAdapter;
    private ArrayList<CustomTabEntity> entities = new ArrayList<>();
    private List<Fragment> fragments = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_main);

//        binding = ActivityMainBinding.inflate(getLayoutInflater());
//        setContentView(binding.getRoot());
//        ImageOptions options = new ImageOptions.Builder()
//                .setPlaceImage(R.drawable.ic_launcher_background)
//                .setErrorImage(R.drawable.ic_launcher_foreground)
//                .build();
//
//
//        String url="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202107%2F18%2F20210718002444_9d6fd.thumb.1000_0.jpg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1665639315&t=975c58d64a2c3218058dcde696c0c9ee";
//        ImageLoaderManager.getInstance().loadImage(this,R.drawable.ic_launcher_background,options,binding.ivTest);
        initView();
    }

    //初始化View
    private void initView() {
        entities.add(new MyTabBean("",0,0));
        entities.add(new MyTabBean("",0,0));
        entities.add(new MyTabBean("",0,0));
        binding.comm.setTabData(entities);

        fragments.add(new OneFragment());
        fragments.add(new TwoFragment());
        fragments.add(new ThreeFragment());
        viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(),fragments);
        binding.mViewPager.setAdapter(viewPagerAdapter);

        binding.comm.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                binding.mViewPager.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });

        binding.mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                binding.comm.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

}